#pragma once
#include "vn/MemoryStream.h"
#include "tests/stub_StreamTest.h"

void MemoryStreamTest() {_test_func_;
	{
		MemoryStream a("0123456789", 10);
		assert(a.CanRead() == true);
		assert(a.CanSeek() == true);
		assert(a.CanWrite() == false);
		assert(a.GetLength() == 10);
		assert(a.GetPosition() == 0);

		assert(a.Seek(1, SeekBegin) == 1);
		assert(a.Seek(11, SeekBegin) == 11);

		a.Seek(0, SeekBegin);
		REQUIRE_EXCEPTION( a.Seek( -1, SeekBegin)   );
		assert(a.GetPosition() == 0);
		REQUIRE_EXCEPTION( a.Seek(-11, SeekEnd)     );
		assert(a.GetPosition() == 0);
		REQUIRE_EXCEPTION( a.Seek(-11, SeekCurrent) );
		assert(a.GetPosition() == 0);

		a.Seek( 5, SeekBegin);
		a.Seek(-1, SeekCurrent);
		a.Seek(+1, SeekCurrent);

		int buf;
		a.Read((Buf8 *)&buf, 4);
		assert(a.GetPosition() == 9);
	}
}
